<template>
	<view class="content">
		<tn-toast ref="toast"></tn-toast>
		<view class="content_top">
			<image class="background-image" src="../../static/img/bg.png"></image>
			<view class="content_top_box">
				<view class="content_top_box_left">
					<view class="content_top_box_left_hi">
						Hi~
					</view>
					<view class="content_top_box_left_name">
						{{name}}
					</view>
				</view>
				<view class="content_top_box_right">

					<tn-avatar size="xl" @click="onImageClick(RLZP_FJ)" :src="RLZP_FJ"></tn-avatar>
				</view>
			</view>
		</view>
		<view class="content_bottom">
			<view class="content_bottom_xm" v-if="showNull " style="text-align: center;">
				<image src="../../static/img/nullproject.png" style="width: 270rpx;height: 188rpx"></image>
			</view>
			<view class="content_bottom_xm" v-else>
				<view class="content_bottom_xm_img">
					<image src="../../static/img/indexbac.png" mode="widthFix" style="width: 134rpx;"></image>
				</view>

				<view class="content_bottom_xm_name">
					项目名称：{{BIDDING_PROJECT_NAME}}
				</view>
				<view class="content_bottom_xm_fjname">
					分建工程名称：{{SUBPACKAGE_PROJECT_NAME}}
				</view>
				<view class="content_bottom_xm_dept">
					单位：{{AFFILIATED_PROJECT_FIRM}}
				</view>
				<view class="content_bottom_xm_time">
					首次进场时间：{{firstTime}}
				</view>
			</view>

			<view class="content_bottom_list">
				<view class="content_bottom_list_dj" @click="toRegistrationSuccessful()">
					<view class="content_bottom_list_dj_left">
						<view class="content_bottom_list_dj_left_name">
							每日出入登记
						</view>
						<view class="content_bottom_list_dj_left_detail">
							出入工地登记
						</view>
					</view>
					<view class="content_bottom_list_dj_right">
						<image src="../../static/img/churu.png" style="width: 95rpx;height: 91rpx;"></image>
					</view>
				</view>
			</view>
			<view class="content_bottom_title">
				上海市基础工程集团有限公司
			</view>
		</view>
		<TabBar selectedIndex=0></TabBar>


	</view>
</template>

<script>
	import {
		BASE_URL
	} from '../../utils/request.js'
	import TabBar from "../../components/tabbar.vue";
	export default {
		components: {
			TabBar
		},
		data() {
			return {
				activeColor: "#fa3534", // 选中时的颜色
				inactiveColor: "#000", // 未选中时的颜色
				name: '',
				RLZP_FJ: '',
				BIDDING_PROJECT_NAME: '',
				SUBPACKAGE_PROJECT_NAME: '',
				AFFILIATED_PROJECT_FIRM: '',
				firstTime: '',
				showNull: false,
				ZT: '0',
				BUYING_TASK_NO: '',
				PROJECT_NO: ''

			}
		},
		computed: {


		},
		onLoad() {

		},
		onShow() {
			// ⭐隐藏pages.json里配置的导航栏，使用封装的tabbar组件
			uni.hideTabBar({
				animation: false
			})
			this.getdetail();
		},
		mounted() {
			// 在页面加载完成后调用 uni.hideTabBar() 方法来隐藏分包管理人员的 tabBar
			// uni.hideTabBar({
			//   animation: true, // 可选，是否需要动画效果，默认为 true
			//   success: function() {
			//     console.log('成功隐藏分包管理人员的 tabBar');
			//   },
			//   fail: function(err) {
			//     console.error('隐藏分包管理人员的 tabBar 失败：', err);
			//   }
			// });
			this.getdetail();
		},
		methods: {
			onImageClick(imageUrl) {
				console.log(imageUrl, 'imageUrl')
				const current = imageUrl;
				uni.previewImage({
					current: current, // 当前显示图片的链接
					// urls 数组只需要包含当前图片的URL，因为只预览一张
					urls: [current]
				});

			},
			async getdetail() {
				try {
					const url = '/portal/r/w'; // 替换为你的 API 地址
					const params = {
						// 构造你的请求参数
						// 
						// sid:'5555555555555555' ,
						sid: uni.getStorageSync('SID'),
						cmd: 'sfeg.srm.workers.join.apply.queryApproachInformation',
						openId: uni.getStorageSync('OPEN_ID'),
						phone: uni.getStorageSync('phoneNumber')
					};

					// 发送 POST 请求
					const response = await this.$get(url, params);
					console.log(response,'response')
					if (response.msg == '没有查询到该员工信息') {
						this.$refs.toast.show({

							content: '没有查询到该员工信息！',
							icon: 'error', // 不显示图标
							duration: 2000 // 显示时长 2000ms
						});

						uni.removeStorageSync('SID');
						uni.removeStorageSync('UNIONID');
						uni.removeStorageSync('OPEN_ID');
						uni.removeStorageSync('IS_LEADER');
						uni.removeStorageSync('scrollHeight');
						uni.removeStorageSync('phoneNumber');
						uni.removeStorageSync('BOID');
						uni.removeStorageSync('IMG_NAME');
						uni.removeStorageSync('SF_GL');
						uni.removeStorageSync('wxcd');
						uni.removeStorageSync('wxcdID');
						uni.removeStorageSync('fsignPhoto');
						uni.removeStorageSync('fsignPhotoName');
						uni.removeStorageSync('savedData');
						uni.removeStorageSync('AGE');
						uni.removeStorageSync('DOWNLOADURL');
						uni.removeStorageSync('DOWNLOADURLName');
						uni.removeStorageSync('ID_CARD');
						uni.removeStorageSync('NATION');
						uni.removeStorageSync('SEX');
						uni.removeStorageSync('USER_NAME');
						uni.removeStorageSync('DOWNLOADURLDown');
						uni.removeStorageSync('lwphoto');
						uni.removeStorageSync('lwphotoName');
						uni.removeStorageSync('photoBOID');
						uni.redirectTo({
							url: '../loginIndex/loginIndex'
						});


					} else {
						uni.setStorageSync('USER_NAME', response.data.USER_NAME);
						uni.setStorageSync('lwphoto', response.data.RLZP_FJ);
						// 处理请求成功的逻辑
						console.log('请求成功个人数据', response);
						this.name = response.data.USER_NAME;
						this.isApproachApply = response.data.isApproachApply;
						this.RLZP_FJ = BASE_URL + '/portal/r' + response.data.RLZP_FJ.slice(1);
						this.isQuitApply = response.data.isQuitApply;
						this.isUpdate = response.data.isUpdate;
						this.ZT = response.data.ZT;

						if (response.data.BIDDING_PROJECT_NAME == '' || response.data.BIDDING_PROJECT_NAME ==
							undefined) {
							this.showNull = true;
						} else {
							this.showNull = false;

							this.BIDDING_PROJECT_NAME = response.data.BIDDING_PROJECT_NAME;
							this.SUBPACKAGE_PROJECT_NAME = response.data.SUBPACKAGE_PROJECT_NAME;
							this.AFFILIATED_PROJECT_FIRM = response.data.AFFILIATED_PROJECT_FIRM;
							this.firstTime = response.data.firstTime;
							this.PROJECT_NO = response.data.PROJECT_NO;
							this.PHONE_NUMBER = response.data.PHONE_NUMBER;
							this.USER_NAME = response.data.USER_NAME;
							this.BUYING_TASK_NO = response.data.BUYING_TASK_NO;


						}
					}


				} catch (error) {
					// 处理请求失败的逻辑
					console.error('请求失败', error);
				}
			},
			toRegistrationSuccessful() {
				console.log('55555')
				var that = this;
				if (that.ZT == '1') {

					uni.scanCode({
						success: function(res) {
							let qrcodeResult = res.result;

							if (qrcodeResult.slice(-2) !== "@@") {
								console.log('正确了')
								// 提取@@前的数据
								var dataBeforeAt = qrcodeResult;
								// var dataBeforeAt = qrcodeResult.slice(0, -2);
								// 获取用户当前位置
								uni.getLocation({
									type: 'wgs84', // 默认为 wgs84 的 gps 坐标，如果要返回直接给 openLocation 用的火星坐标，可传入 'gcj02'
									success: async function(location) {
										console.log('获取位置成功', location);
										// location 对象包含经纬度信息：latitude（纬度）和 longitude（经度）
										var latitude = location.latitude;
										var longitude = location.longitude;

										try {
											const url = '/portal/r/w'; // 替换为你的 API 地址
											const params = {
												// 构造你的请求参数
												sid: uni.getStorageSync('SID'),
												cmd: 'sfeg.srm.workers.join.apply.dailyEntry',
												openId: uni.getStorageSync('OPEN_ID'),
												phone: uni.getStorageSync('phoneNumber'),
												uaInfo: '555555',
												projectNo: dataBeforeAt,
												subPackageNo: that.BUYING_TASK_NO,
												longitudeLatitude: longitude + ',' + latitude
											};

											// 发送 POST 请求
											const response = await that.$get(url, params);

											// 处理请求成功的逻辑
											console.log('出入登记成功', response);
											let obj = response.data;
											if (response.result == 'ok') {
												uni.navigateTo({
													url: '../registrationSuccessful/registrationSuccessful?data=' +
														JSON.stringify(obj)
												});
											} else {
												console.log('失败去哪里')
												uni.navigateTo({
													url: '../registrationError/registrationError'
												});
											}



										} catch (error) {
											// 处理请求失败的逻辑
											console.error('请求失败', error);
										}
									},
									fail: function(err) {
										console.error('获取位置失败', err);
										// 定位失败可以执行的操作，比如提示用户
										that.$refs.toast.show({

											content: '定位失败，请检查您的位置信息设置',
											icon: 'error', // 不显示图标
											duration: 2000 // 显示时长 2000ms
										});


										// 仍然可以导航到错误页面
										// uni.navigateTo({
										//   url: '../registrationError/registrationError'
										// });
									}
								});
								// 进行页面跳转并携带参数
								// uni.navigateTo({
								//     url: '../entry/entry?data=' + dataBeforeAt
								// });
							} else {

								that.$refs.toast.show({

									content: '请扫描正确的二维码',
									icon: 'error', // 不显示图标
									duration: 2000 // 显示时长 2000ms
								});
							}


						},
						fail: function(err) {
							that.$refs.toast.show({

								content: '扫码失败，请重新扫码',
								icon: 'error', // 不显示图标
								duration: 2000 // 显示时长 2000ms
							});
							console.error('扫码失败', err);
							// uni.navigateTo({
							// 	url: '../registrationError/registrationError'
							// });
						}
					});
				} else {
					that.$refs.toast.show({

						content: '非在场人员，禁止登记',
						icon: 'error', // 不显示图标
						duration: 2000 // 显示时长 2000ms
					});
				}


			},

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: 100vh;
		/* 占据整个视口高度 */
		display: flex;
		flex-direction: column;
		position: relative;
		/* 相对定位，以便子元素可以相对于它定位 */
	}

	.content_top {

		position: relative;
		/* 设置相对定位，以便子元素可以相对于它定位 */
		width: 100%;
		/* 宽度百分之百 */
		height: 500rpx;
		/* 设置高度 */
		overflow: hidden;

		/* 触发 BFC */
		.background-image {
			position: absolute;
			/* 设置绝对定位，让背景图充满整个父容器 */
			top: 0;
			left: 0;
			width: 100%;
			/* 宽度百分之百 */
			height: 100%;
			/* 高度百分之百 */
			object-fit: cover;
			/* 图片填充父容器 */
			z-index: -1;
			/* 将背景图放到底层 */
		}

		.content_top_box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 73rpx 73rpx 0 73rpx;

			.content_top_box_left {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 48rpx;
				color: #FFFFFF;
			}

			.content_top_box_right {}
		}
	}

	.content_bottom {
		flex: 1;
		/* 自动填充剩余空间 */
		position: absolute;
		/* 绝对定位，覆盖在 .content_top 上方 */
		top: 295rpx;
		/* 位于父容器顶部下方 200rpx 处 */
		width: 100%;
		/* 宽度百分之百 */
		height: calc(100% - 295rpx);
		/* 高度占满父容器下方 */
		background-color: #F8F9FD;
		/* 背景色，可根据需要修改 */
		z-index: 0;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;

		/* 确保在 content_top 之下 */
		// display: flex;
		// justify-content: center;
		// align-items: center;
		.content_bottom_xm {
			background: #F1FAFF;
			box-shadow: 0rpx 7rpx 10rpx 0rpx rgba(0, 0, 0, 0.04);
			border-radius: 16rpx;
			margin: 33rpx;
			position: relative;
			/* padding: 52rpx;wxcs_style_padding; */
			padding: 28rpx 27rpx 28rpx 27rpx;

			.content_bottom_xm_name {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #3A3A3A;
			}

			.content_bottom_xm_fjname {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				margin-top: 28rpx;
			}

			.content_bottom_xm_dept {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				margin-top: 28rpx;
			}

			.content_bottom_xm_time {
				font-family: PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				margin-top: 28rpx;
			}

			.content_bottom_xm_img {
				position: absolute;
				right: 37rpx;
				bottom: 37rpx;
			}
		}

		.content_bottom_title {

			font-family: PingFang SC;
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
			/* margin-top: auto; */
			text-align: center;
			position: absolute;
			bottom: 37rpx;
			left: 27%;
		}

		.content_bottom_list {
			margin: 33rpx;

			.content_bottom_list_dj {
				display: flex;
				align-items: center;
				justify-content: space-between;
				background: #FFFFFF;
				box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(0, 0, 0, 0.06);
				border-radius: 21rpx;
				padding: 33rpx;

				.content_bottom_list_dj_left {
					.content_bottom_list_dj_left_name {
						font-family: PingFang SC;
						font-weight: bold;
						font-size: 36rpx;
						color: #333333;
					}

					.content_bottom_list_dj_left_detail {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #999999;
						margin-top: 24rpx;
					}
				}
			}
		}

	}
</style>